﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Genealogy_Builder
{
    public partial class PlaceEditor : Form
    {

        public PlaceEditor(List<Place> Places)
        {
            InitializeComponent();
            foreach (Place p in Places)
            {
                lbPlaces.Items.Add(p);
            }
        }

        public List<Place> AddPlaces()
        {
            ShowDialog();
            List<Place> LP = new List<Place>();
            foreach (Place p in lbPlaces.Items)
            {
                LP.Add(p);
            }
            return LP;
        }

        private void btnRemovePlace_Click(object sender, EventArgs e)
        {
            if (lbPlaces.SelectedItem != null)
            {
                string itmName = lbPlaces.SelectedItem.ToString();
                DialogResult result;
                result = MessageBox.Show("Are you sure you want to delete " + itmName + "?", "Remove Place", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    lbPlaces.Items.Remove(lbPlaces.SelectedItem);
                }
            }
        }

        private void btnAddPlace_Click(object sender, EventArgs e)
        {
            PlaceDialog PD = new PlaceDialog();
            if (PD.AddPlace() && PD.newPlace != null)
            {
                lbPlaces.Items.Add(PD.newPlace);
            }
        }

    }
}
